/*******************************************************************
 * 
 *  Copyright C 2005 by Amlogic, Inc. All Rights Reserved.
 *
 *  Description: 
 *
 *  Author: Amlogic Software
 *  Created: 2007-02-11 10:56
 *
 *******************************************************************/

#include "burner_device.h"
#include "upgrade_img.h"
#define  TASK_STK_SIZE                 2048       /* Size of each task's stacks (# of WORDs)            */
#define  TASK_NANDRW_PRIO                  5
#define  TASK_NANDFILE_PRIO                10
#include <bsp.h>
//#define  TASK_STB_SENDER_PRIO           25


OS_STK burner_stack[TASK_STK_SIZE];
INT16U taskid;


//unsigned ramdisk_buffer[512*64/4];
extern unsigned char burn_code[];
extern unsigned burn_code_len;
avfs_ramdisk_config avfs_ramdisk_configuration[]=
{
 {512,64, (void*)burn_code}
};
int avfs_ramdisk_configuration_size =1 ;

/****************************************************************
    NAND_TEST Task 2 : File Test
****************************************************************/
//extern const SystemDescription system_desc;
#define BURNER_PROGRAM
#include "../out_parameter.c"
void burner_task(void *arg)
{
	INT8U err;

	AVSysEvent_Init();

	AVIoinit();
	AVBurnerInitDev();
	upgrade_image_file(&system_desc,"/dev/ramdisk0",0);
	printf("Burn OK \n");
	while (1) {
	} /* while (1) */
}

/****************************************************************
 Task conmmunications
****************************************************************/
#define wr(reg, val) *(volatile unsigned *)(reg) = (val)		

int main(void)
{
	unsigned t;
	/*initial the system for jtag working stabilization*/
	wr(0x01100568,0x00000320);
	wr(0x01100574,0x00000181);
	wr(0x01101d10,0x8000);
	wr(0x01101d14,0x3b0e);
	wr(0x01101c00,0x0500);
	//wr(0x01000590,0x88110);
	_sr(0xff,0x40c);
	t=_lr(0x200);
	t&=~(1<<5);
	t|=(1<<6);	
	_sr(t,0x200);
	
	avfs_ramdisk_configuration[0].block_num=(burn_code_len+511)>>9;
		
    /* kernal OS init */
    AVInit();

    /* memory library init */
    AVMemInit();

    AVTaskCreate(burner_task, 0, &burner_stack[TASK_STK_SIZE - 1], TASK_NANDFILE_PRIO, &taskid);
#ifndef  __ROM_
    AVOS_Check_Flag=0;
#endif 
    AVStart();

    return 0;

}
//INT8U         AVTaskCreate(void (*task)(void *pd), void *pdata, OS_STK *ptos, INT8U prio, INT16U *id)
//{
//	return AVTaskCreate_trace(task,pdata,ptos,prio,id, __LINE__, __FILE__);
//	
//}
//void *AVMem_malloc(size_t size)
//{
//	return (void *)AVMem_malloc_trace(size, __LINE__, __FILE__);
//}
//void AVMem_free(void *ptr)
//{
//	AVMem_free_trace(ptr, __LINE__, __FILE__);
//}



